<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{/js/jquery-3.3.1.js}"></script>
    <script type="text/javascript">
        function fun3() {
            $.post({
                url:"/register",
                data:{"name":$("#name").val()},
                success:function (data) {
                    if (data.toString()==='用户名已存在'){
                        $("#userInfo").css("color","red");
                    }
                    $("#userInfo").html(data);
                }
            })
        }
    </script>
</head>
<body>
<p>
    用户名：<input type="text" id="name" onblur="fun3()">
    <span id="userInfo"></span>
</p>
</body>
</html>